<?php
class Merchant_Model_ReceivingLog
{

	private $_table;
	public function __construct(){
		$this->_table = new Merchant_Model_DbTable_ReceivingLog();
	}

	public function add($row){
		return $this->_table->insert($row);
	}

	public  function update($row,$value,$field='rl_id'){
		$where = $this->_table->getAdapter()->quoteInto("{$field} = ?",$value);
		return $this->_table->update($row, $where);

	}

	public function delete($value,$field='rl_id'){
		$where = $this->_table->getAdapter()->quoteInto("{$field} = ?", $value);
		return $this->_table->delete($where);
	}

	public function getByValue($value,$field='rl_id'){
        $select = $this->_table->getAdapter()->select();
        $table  = $this->_table->info('name');
        $select->from($table,'*');
        $select->where("{$field} = ?",$value);
		return $this->_table->getAdapter()->fetchRow($select);
	}

	public function getByCond($cond,$type='*',$order='',$count=20, $offset=0){
		$table = $this->_table->info('name');
		$select = $this->_table->select()->from($table, $type);
		$select->where('customer_id = ?',$cond['customer_id']);
		if(isset($cond['receiving_code']) && $cond['receiving_code'] !=''){
			$select->where('receiving_code = ?',$cond['receiving_code']);
		}
		if('count(*)'==$type){
            return $this->_table->getAdapter()->fetchOne($select);
        }
        if ($count==0){        	
        	return $this->_table->fetchAll($select)->toArray(); 
        }
		$select->order($order);
		$select->limit($count,$offset);
	
		return $this->_table->fetchAll($select)->toArray();
	}

}